package com.song.cloud.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.song.cloud.common.entities.CommonResult;
import com.song.cloud.order.config.configOpenFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author ZhangGuisong
 * @Date 2021/3/2-19:29
 */
@RestController
public class paymentController {
    private String uri = "http://sentinel-provider-service";
    @Resource
    private configOpenFeign configOpenFeign;


    @GetMapping("/getTest/{id}")
    @SentinelResource(value="getTest",blockHandler="deal_snetinel")
    public CommonResult getTest(@PathVariable("id") Integer id) {
       // CommonResult result = restTemplate.getForObject(uri + "/getData/" + id, CommonResult.class);
        CommonResult data = configOpenFeign.getData(id);
        if (id == 4) {
            throw new IllegalArgumentException("参数异常");
        } else if (data == null) {
            throw new NullPointerException("空指针异常");
        }
        return data;
    }
    public CommonResult deal_snetinel(@PathVariable("id") Integer id, BlockException blockException){

        return  new CommonResult(444,"this method for solve sentinel","message");
    }
    public CommonResult deal_method(@PathVariable("id") Integer id){
        return  new CommonResult(443,"this method for solve methodException","message");
    }
}

